<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/2/23
 * Time: 15:29
 */

namespace app\api\controller\driver;
use app\base\logic;
use app\base\service\Redis;

/**
 * @name【后台调用】
 * @baseurl【driver.index】
 * @file【driver/Admin.php】
 */
class Admin extends Base
{
    protected $beforeActionList = [];

    public function getRedisBeidou(){
        $data = [];
        $data['data'] = $this->getRedisData();
        return $this->retSucc($data);
    }
    
    public function getRedisData() {
        $redis  = Redis::getInstance();
		$prefix = 'pccx.beidou*';
        $ret    = $redis->scan($prefix);
        if(empty($ret)){
            return $this->retError(123);
        }
        $brr     = [];
        $nowTime = time();
        $cars    = [];
        foreach($ret as $v){
            $arr              = $this->redis->get($v);
            $arr              = json_decode($arr,true);
            if(empty($arr['carno'])){
                continue;
            }
            if($nowTime - $arr['time'] > 15*60 ){
                $arr['alarm'] = '终端没电';
                $arr['state'] = ' 停止 离线 不定位';
            }
            list($arr['lon'],$arr['lat']) = (new logic\Coordinate())->wgsTOgcj($arr['lon'],$arr['lat']);
            $brr[]            = $arr;
        }
        return $brr;
	}
	
	public function setCarState(){
		
		$cars = $this->getRedisBeidou();
		$busy = [];
		if($cars) {
			foreach($cars AS $car) {
				$car['time'] > time() - 600 && $busy[] = $car['carno'];
			} 
		}
		halt($busy);
		
	}
	
}